🩹 [Patch]: Reserved words in Lua input now detected with option to skip validation#6
Conversation
Super-linter summary
Super-linter detected linting errors For more information, see the GitHub Actions workflow run Powered by Super-linter POWERSHELL |
…e error message for reserved words in Read-LuaTable
Super-linter summary
Super-linter detected linting errors For more information, see the GitHub Actions workflow run Powered by Super-linter POWERSHELL |
…onvertFrom-Lua hashtable; resolve indentation inconsistency in Read-LuaTable by inlining throw message
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
There was a problem hiding this comment.
Pull request overview
This PR tightens ConvertFrom-Lua parsing to detect Lua reserved words when they are used as bare identifier table keys or assignment variable names, with a new -SkipValidation switch to downgrade those errors to warnings for lenient imports. It also attempts to fix enum string serialization to avoid double-escaping backslashes.
Changes:
- Add
-SkipValidationtoConvertFrom-Luaand thread it into the private parser via script-scoped state. - Validate reserved words in
Read-LuaTable(table keys) andConvertFrom-LuaTable(assignment variables), erroring by default or warning when-SkipValidationis used. - Adjust enum string escaping logic in
ConvertTo-LuaTableand add tests covering strict/warn behaviors.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Lua.Tests.ps1 | Adds tests for reserved-word validation and -SkipValidation warning behavior. |
| src/functions/public/Lua/ConvertFrom-Lua.ps1 | Adds -SkipValidation and passes it into the private parser. |
| src/functions/private/Read-LuaTable.ps1 | Adds reserved-word validation for bare identifier keys inside table constructors. |
| src/functions/private/ConvertFrom-LuaTable.ps1 | Adds reserved-word validation for assignment variable names and stores skip flag in script scope. |
| src/functions/private/ConvertTo-LuaTable.ps1 | Modifies enum string escaping behavior for backslashes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…Lua §3.1; add tests for capitalized identifiers (End, While)
Super-linter summary
All files and directories linted successfully For more information, see the GitHub Actions workflow run Powered by Super-linter |
|
✅ New release: PowerShell Gallery - Lua 1.0.1 |
|
✅ New release: GitHub - Lua v1.0.1 |
ConvertFrom-Luanow validates that bare identifier keys and variable names are not Lua reserved words, throwing a clear error by default. A new-SkipValidationswitch allows lenient import of out-of-spec data, emitting per-occurrence warnings instead. Enum string serialization no longer double-escapes backslashes.Changed: Reserved word validation on deserialization
ConvertFrom-Luanow rejects bare reserved words used as table keys or assignment variable names — matching the Lua 5.4 §3.1 grammar rules. Previously, invalid Lua like{ end = 1 }orwhile = 42was silently parsed.Bracket-notation keys with reserved word strings remain fully supported:
New:
-SkipValidationswitch for lenient importWhen importing data that may not be spec-compliant, use
-SkipValidationto suppress errors. Each reserved word occurrence produces its own warning, and parsing continues normally.Fixed: Enum string escaping no longer double-escapes backslashes
ConvertTo-Lua -EnumsAsStringspreviously produced\\\\instead of\\for backslashes in enum string representations due to an incorrect-replacepattern.Technical Details
ConvertFrom-Lua.ps1: Added-SkipValidationswitch parameter, threaded toConvertFrom-LuaTablevia-SkipValidation:$SkipValidation.ConvertFrom-LuaTable.ps1: Added-SkipValidationparameter. Stored as$script:luaSkipValidationfor use by recursive parser functions. Added$reservedWordsarray and validation after variable name extraction in the assignment parsing path — throws or warns based on skip flag.Read-LuaTable.ps1: Added$reservedWordsarray and validation after bare identifier +=detection — throws or warns based on$script:luaSkipValidation.ConvertTo-LuaTable.ps1: Fixed enum escaping:-replace '\\', '\\\\'→-replace '\\', '\\'.returnkeyword note:returnis consumed as a leading keyword before assignment detection (forreturn { ... }patterns), soreturn = 42triggers a different parse error rather than the reserved word check. Tests usewhileas the second assignment variable test word.-SkipValidation(bare key warning, assignment warning, multiple warnings with count assertion)."